/**
 * Copyright (c) 2024-2025 National Fundamental Software of China Co., Ltd.
 *
 * You should have find a copy of NFSChina License. If not, please contact us
 * by email <os_support@nfschina>
 *
**/

#include "contactwidget.h"
#include "companyqrcodedialog.h"

#include <KPluginFactory>
#include <KSharedConfig>
#include <KColorScheme>
#include <QPushButton>

K_PLUGIN_CLASS_WITH_JSON(ContactWidget, "kcm_contact.json")

ContactWidget::ContactWidget(QWidget *parent, const QVariantList &args) :
    KCModule(parent, args)
{
    setupUi(this);

    auto config = KSharedConfig::openConfig();
    auto highlitgtscheme = KColorScheme(QPalette::Active, KColorScheme::Selection, config);
    auto active = KColorScheme(QPalette::Active, KColorScheme::View, config);
    QColor thisbackground = active.background().color();
    QColor highlightcolor = highlitgtscheme.background(KColorScheme::NormalBackground).color();
    QColor textcolor = active.foreground(KColorScheme::NormalText).color();
    QString highlightcolorstr = QString("rgb(%1, %2, %3)").arg(highlightcolor.red()).arg(highlightcolor.green()).arg(highlightcolor.blue());
    QString themebackground = QString("rgb(%1, %2, %3)").arg(thisbackground.red()).arg(thisbackground.green()).arg(thisbackground.blue());
    QString themetext = QString("rgb(%1, %2, %3)").arg(textcolor.red()).arg(textcolor.green()).arg(textcolor.blue());
    QString IconStr = themebackground=="rgb(255, 255, 255)"?"logo_pt.png":"logo_ss.png";

    label->setStyleSheet(QString("image:url(:/icons/%0);").arg(IconStr));

    QPushButton *button = new QPushButton(frame_2);
    button->setStyleSheet("QPushButton { background-color: transparent;border: 0px solid gray;}");
    button->setFixedSize(589,48);
    button->move(0,144);

    QPushButton *tailicon1 = new QPushButton(button);
    tailicon1->setIcon(QIcon::fromTheme(QStringLiteral("go-next")));
    //tailicon1->setGeometry(button->x()+591-16-20, button->height() - tailicon1->height() + 1, 16, 16);
    tailicon1->setGeometry(560, 16, 16, 16);
    tailicon1->setStyleSheet(QString("\
                                    QPushButton{ \
                                        background-color: transparent;\
                                        border : 0px;\
                                    }\
                                    "));
    connect(tailicon1,&QPushButton::clicked,button,&QPushButton::clicked);

    QPushButton *button1 = new QPushButton(frame_2);
    button1->setStyleSheet("QPushButton { background-color: transparent;border: 0px solid gray;}");
    button1->setFixedSize(589,48);
    button1->move(0,192);

    QPushButton *tailicon2 = new QPushButton(button1);
    tailicon2->setIcon(QIcon::fromTheme(QStringLiteral("go-next")));
    tailicon2->setGeometry(560, 16, 16, 16);
    tailicon2->setStyleSheet(QString("\
                                    QPushButton{ \
                                        background-color: transparent;\
                                        border : 0px;\
                                    }\
                                    "));

    bool isLight = themebackground=="rgb(255, 255, 255)";

    QString frameStyle;

    if (isLight) {
        frameStyle = R"(
            QFrame#frame_2 {
                background-color: #FFFFFF;
                border-radius: 10px;
                border: 1px solid #CCCCCC;
            }
            QFrame[frameShape="4"] {
                border-top: 1px solid #F0F0F0;
                background: none;
            }
        )";
    } else {
        frameStyle = R"(
            QFrame#frame_2 {
                background-color: #353535;
                border-radius: 10px;
                border: 1px solid #2D2D2D;
            }
            QFrame[frameShape="4"] {
                border-top: 1px solid #2D2D2D;
                background: none;
            }
        )";
    }

    this->setStyleSheet(frameStyle);

    line->setFrameShape(QFrame::HLine);
    line_2->setFrameShape(QFrame::HLine);
    line_3->setFrameShape(QFrame::HLine);
    line_4->setFrameShape(QFrame::HLine);

    connect(tailicon2,&QPushButton::clicked,button1,&QPushButton::clicked);

    connect(button,&QPushButton::clicked,
                                    [=]()
    {
        int num = 1;
        CompanyQRCodeDialog codedialog(num,this);
        codedialog.exec();
    });

    connect(button1,&QPushButton::clicked,
                                    [=]()
    {
        int num = 2;
        CompanyQRCodeDialog codedialog(num,this);
        codedialog.exec();
    });
}

ContactWidget::~ContactWidget()
{

}

void ContactWidget::load()
{

}

void ContactWidget::save()
{

}

void ContactWidget::defaults()
{

}


#include "contactwidget.moc"
